package com.mazaiting.web.converter;

import com.alibaba.fastjson.JSON;
import com.mazaiting.web.domain.base.IBaseVO;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.lang.NonNull;

/**
 * 字符串转换为对象
 * 解决多层对象转换异常问题
 * @author mazaiting
 * @create_time 2022/10/24 13:27
 */
public class String2BaseVOConverterFactory implements ConverterFactory<String, IBaseVO> {

    @NonNull
    @Override
    public <T extends IBaseVO> Converter<String, T> getConverter(@NonNull Class<T> targetType) {
        return source -> JSON.parseObject(source, targetType);
    }
}
